/**
 * @Description: 挂载模块  挂载模块需要先在 routes新增路由  然后再api文件新增模块
 * @author longfa liang
 * @date 2021/7/13
 */



var fs = require("fs")
var config = require("../config/config")
/**
 * 自动读取文件加载路由
 * @param app
 */

console.log("配置挂载模块", config.startServer.toString())
module.exports = function (app) {
    let list = fs.readdirSync("routes")
    for (var i = 0; i < list.length; i++) {
        for (var j = 0; j < config.startServer.length; j++) {
            if (config.startServer[j] == list[i].split(".")[0]) {
                var usersRouter = require('../routes/' + list[i]);
                if (usersRouter.params.name) {
                    console.log(usersRouter.params.name, " 挂载成功")
                }
                app.use('/' + list[i].split(".")[0], usersRouter);
            }
        }
    }
}
